package com.lys.oss.controller;

import com.lys.commonutils.R;
import com.lys.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Lyyyys
 * @version 1.0
 * @date 2021/3/30 15:07
 */
@Api(description="阿里云文件管理")
@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    /*
     * @MethodName:uploadOssFile
     * @Description:上传头像的方法
     * @Params: [file]
     * @Return: com.lys.commonutils.R
     * @Author: Lyyyys
     * @Date: 2021/3/30 15:12
     */
    @PostMapping("upload")
    public R uploadOssFile(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file){
        String uploadUrl = ossService.upload(file);
        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);
    }
}
